home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-21 | 10.4 KB | 319 lines | [TEXT/MPS ] |
- // UObject.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UOBJECT__
- #define __UOBJECT__
-
- // MacApp
-
- #ifndef __MACAPPTYPES__
- #include "MacAppTypes.h"
- #endif
-
- #ifndef __UCLASSDESC__
- #include "UClassDesc.h"
- #endif
-
- #ifndef __UPOINTEROBJECT__
- #include "UPointerObject.h"
- #endif
-
- // ANSI
-
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class TObject;
- class TStream;
- class TDependencySpace;
-
- //----------------------------------------------------------------------------------------
- // Typedefs
- //----------------------------------------------------------------------------------------
-
- enum ComparisonResult
- {
- kLessThan = -1,
- kEqual = 0,
- kGreaterThan = 1
- };
-
- typedef long HashValue;
-
- //BEGIN Added by C Kopala 6/14/96
- #if qDebug
- extern long gObjectCount;
- extern Boolean gObjectCountingEnabled;
- extern Boolean gPrintBaseClassInfo;
- extern Boolean gPrintMacAppClassInfo;
- extern Boolean gPrintAppClassInfo;
- extern Boolean gAppUserFlag1;
- extern Boolean gAppUserFlag2;
- extern Boolean gAppUserFlag3;
- #endif
- //END Added by C Kopala 6/14/96
- //----------------------------------------------------------------------------------------
- // TObject: Definition of the system's root object
- //----------------------------------------------------------------------------------------
-
- #if (qDebug || qSym) && defined(__MWERKS__)
- #define qForceClassIDFirstHack 1
-
- // make sure CodeWarrior puts fClassID first, not the vtable
- struct ForceClassIDFirst
- {
- ClassID fClassID;
- };
- #else
- #define qForceClassIDFirstHack 0
- #endif
-
- #if qForceClassIDFirstHack
- class TObject : public ForceClassIDFirst
- #else
- class TObject
- #endif
- {
- MA_DECLARE_CLASS;
-
- public:
-
- #if (qDebug || qSym) && !qForceClassIDFirstHack
- ClassID fClassID; // Used to do object validation in debug mode.
- #endif
-
- //------------------------------------------------------------------------------------
- // Allocate and deallocate.
- //------------------------------------------------------------------------------------
-
- void* operator new(size_t size);
- void operator delete(void* obj);
-
- //------------------------------------------------------------------------------------
- // Initializer and I<Method>.
- //------------------------------------------------------------------------------------
-
- TObject();
- // Constructor
-
- virtual ~TObject();
- // Destructor
-
- void IObject();
- // The ancestral initializer. Should be called in the I<ClassName> chain. i.e.
- // IView -> IEventHandler -> IObject, followed by a called to <ClassName> i.e without
- // the T.
-
- //BEGIN Added by C Kopala 6/14/96
- #if qDebug
- void PrintConstructorClassInfo();
- void PrintDestructorClassInfo();
- void PrintAppConstructorClassInfo();
- void PrintAppDestructorClassInfo();
- #endif
- //END Added by C Kopala 6/14/96
- //------------------------------------------------------------------------------------
- // Comparison
- //------------------------------------------------------------------------------------
-
- HashValue Hash() const;
-
- virtual Boolean IsSame(const TObject* theObject) const;
- // Does a handle comparison to determine if the objects are in fact the same object
-
- virtual Boolean IsEqual(const TObject* theObject) const;
- // Must be overridden to be useful. Default implementation calls IsSame
-
- virtual ComparisonResult CompareObject(const TObject* theObject) const;
- // Compares two objects.
-
- virtual Boolean IsGreaterThan(const TObject* obj) const;
-
- virtual Boolean IsLessThan(const TObject* obj) const;
-
- Boolean operator<(const TObject& obj) const;
- // Calls back to IsLessThan.
-
- Boolean operator>(const TObject& obj) const;
- // Calls back to IsGreaterThan.
-
- Boolean operator>=(const TObject& obj) const;
- // Calls back to IsGreaterThan and IsEqual.
-
- Boolean operator<=(const TObject& obj) const;
- // Calls back to IsLessThan and IsEqual.
-
- Boolean operator ==(const TObject& obj) const;
- // Calls back to IsEqual.
-
- Boolean operator !=(const TObject& obj) const;
-
- //------------------------------------------------------------------------------------
- // Change notification
- //------------------------------------------------------------------------------------
-
- void AddDependent(TObject* dependent);
- // Registers the specified object as a dependent of this object in the global
- // dependency space "gMacAppDependencies", so that it will be notified of changes
- // in this object.
-
- void RemoveDependent(TObject* dependent);
- // Remove the specified object from the list of dependents of this object in
- // the global dependency space "gMacAppDependencies".
-
- virtual void Changed(ChangeID theChange, TObject* changedBy);
- // Called to inform dependents of this object in the global dependency space
- // "gMacAppDependencies" that it has been changed.
- // "theChange" will often contain a command number.
- // "changedBy" will often contain a command object.
- // Called often, overridden rarely.
-
- virtual void DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace);
- // Informs this object that an object on which it is dependent in the global
- // dependency space "gMacAppDependencies" has been changed.
- // Called rarely, overridden often.
-
- virtual TDependencySpace* GetDependencySpace();
- // Returns the default dependency space for storing dependents of this object.
- // Returns gMacAppDependencies.
-
- virtual void SetMark(Boolean state);
- // Intended to mark (state=true) or unmark (state=false) this object. Can be used
- // by dependency spaces that require marking, and overridden by objects that store the
- // mark internally. The MacApp dependency spaces do not use this method.
-
- virtual Boolean IsMarked();
- // Intended to return true if this object is marked. Can be used
- // by dependency spaces that require marking, and overridden by objects that store the
- // mark internally. The MacApp dependency spaces do not use this method.
-
- virtual void RemoveAllDependencies();
- // Used by TObject::Free to remove all dependency relations in the global
- // dependency space "gMacAppDependencies" which involve this object, either
- // as notifier or as dependent.
-
- virtual Boolean RemoveDependenciesOnFree();
- // Default is to return true. This will allow us to optimize certain system
- // objects (like TToolBoxEvents).
-
-
-
- //------------------------------------------------------------------------------------
- // Standard signature support.
- //------------------------------------------------------------------------------------
-
- virtual IDType GetStandardSignature(); // override
- // Returns this class's standard signature.
-
- //------------------------------------------------------------------------------------
- // Stream I/O protocol support.
- //------------------------------------------------------------------------------------
-
- virtual void ReadFrom(TStream* aStream);
-
- virtual void WriteTo(TStream* aStream);
-
-
- //------------------------------------------------------------------------------------
- // Miscellaneous protocol and support methods.
- //------------------------------------------------------------------------------------
-
- virtual TObject* Clone();
- // Makes a duplicate copy of this. The default calls this->ShallowClone, which
- // makes a literal copy of instance variables but does not attempt to clone owned
- // objects. A subclass which owns other objects should override this to clone the
- // owned objects and data structures as well.
-
- virtual void Free();
- // Called to dispose of an object. Gives object a chance to cleanup after itself.
- // Default simply calls this->ShallowFree, which makes no attempt to free instance
- // variables. Should be overridden by any class which allocates space or owns
- // other objects in its instance variables.. Be sure to call Inherited!
-
- ClassID GetClassID() const;
- // Returns the class ID of this.
-
- void GetClassName(ClassName& clName) const;
- // Returns the class name of this.
-
- size_t GetClassSize();
- // Returns the basic instantiation size. i.e. the size in bytes of a newly created
- // object of this class.
-
- const ClassDesc* GetSuperClass();
- // Returns ClassDesc for the immediate superclass. Returns NULL for TObject. If we
- // ever get MI this will have to be an enumerator.
-
- Boolean DescendsFrom(const ClassDesc* classDesc) const;
- // True if my class is a subclass of the class described by ClassDesc.
-
- Boolean IsSameClass(const ClassDesc* classDesc);
- // True if my class is the same as the class described by ClassDesc.
-
- virtual TObject* ShallowClone();
- // Lowest level method for copying an object; should not be overridden except in
- // very unusual cases. Simply calls HandToHand to copy the object data.
-
- virtual void ShallowFree();
- // Lowest level method for freeing an object; should not be overridden except in
- // very unusual cases. Simply calls delete to free the object.
-
- void SubClassResponsibility();
- // Called from methods that MUST be overridden in a subclass. Signals failure.
- };
-
-
- typedef TObject* TObjectPtr;
-
- typedef TObjectPtr* TObjectPtrPtr;
-
- typedef TObjectPtrPtr* TObjectPtrHandle;
-
- //BEGIN Added by C Kopala 6/14/96
- #if qDebug
- extern void IncrementObjectCount();
- extern void DecrementObjectCount();
- extern void PrintObjectCount();
- extern void DumpClassInfo();
- extern void DisplayMemoryInfo();
- extern void InitUDebugGlobals();
- #endif
- //END Added by C Kopala 6/14/96
- //----------------------------------------------------------------------------------------
- // INLINES TObject
- //----------------------------------------------------------------------------------------
-
- inline Boolean TObject::operator==(const TObject& obj) const
- {
- return (this->IsEqual(&obj));
- }
-
- inline Boolean TObject::operator!=(const TObject& obj) const
- {
- return (this->IsEqual(&obj) == FALSE);
- }
-
- inline Boolean TObject::operator<(const TObject& obj) const
- {
- return (this->IsLessThan(&obj));
- }
- inline Boolean TObject::operator>(const TObject& obj) const
- {
- return (this->IsGreaterThan(&obj));
- }
- inline Boolean TObject::operator>=(const TObject& obj) const
- {
- return (this->IsGreaterThan(&obj) || this->IsEqual(&obj));
- }
- inline Boolean TObject::operator<=(const TObject& obj) const
- {
- return (this->IsLessThan(&obj) || this->IsEqual(&obj));
- }
-
- #endif
-